package myJs.myPkg.contextMenu

import cats.effect.SyncIO
import japgolly.scalajs.react.CtorType.ChildArg
import japgolly.scalajs.react.{Children, JsFnComponent}
import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

/** Created by yz on 7/2/2022
  */

object MenuItem{

  case class Props(
      onClick: () => Unit,
      disabled: js.UndefOr[Boolean] = js.undefined
  )

  @js.native
  @JSImport("react-contextmenu", "MenuItem")
  object RawComponent extends js.Object {}

  val Component = JsFnComponent[ObjectOrWritten[Props], Children.Varargs](RawComponent)

  def apply(
    onClick: SyncIO[Unit],
    disabled: js.UndefOr[Boolean] = js.undefined
  )(children: ChildArg*) = {
    val useOnClick=()=>onClick.unsafeRunSync()
    Component(Props(useOnClick, disabled))(children: _*)
  }

}
